package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.naming.InitialContext;
import javax.sql.DataSource;

public class DBUtilJNDI {
	public static Connection createConnection (){
		Connection conn = null;
		try {
			InitialContext cxt = new InitialContext();	
			DataSource ds = (DataSource) cxt.lookup( "java:/comp/env/jdbc/myoracle" );
			conn =ds.getConnection();
//			System.out.println(conn);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return conn;
	}
	
	public static void close(Connection conn,PreparedStatement pst,ResultSet rs){
		try {
			if(rs!=null)rs.close();
			if(pst!=null)pst.close();
			if(conn!=null)conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
